# 429 中等：N叉树的层序遍历

"""
# Definition for a Node.
class Node:
    def __init__(self, val=None, children=None):
        self.val = val
        self.children = children


class Solution:
    def levelOrder(self, root: 'Node') -> List[List[int]]:

"""

from collections import deque


def levelOrder(root):
    if not root:
        return []

    q = deque([root])
    ret = []
    while q:
        l = len(q)
        temp = []
        for _ in range(l):
            node = q.popleft()
            temp.append(node.val)
            for child in node.children:
                q.append(child)
        ret.append(temp)

    return ret


print(levelOrder())
